/************************************
*  Copyright (C) 2010 Julien MOTTIN.
*  Contact: julien.mottin@gueydan.eu
*
*  This file is part of Gueydan.
*
*  Gueydan is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  Gueydan is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with Gueydan.  If not, see <http://www.gnu.org/licenses/>.
*
*************************************/
#ifndef BEERXMLHANDLER_H
#define BEERXMLHANDLER_H

// Fwd declarations
class BeerXMLObject;
class QString;
class Hop;
class Fermentable;
class Misc;
class Water;
class Yeast;
class Mash;
class MashStep;
class Style;
class Recipe;
class QDomNode;

class BeerXMLHandler
{
public:
    BeerXMLHandler();
    BeerXMLHandler(BeerXMLObject *ipObject);
    BeerXMLHandler(const BeerXMLObject *ipObject);
    BeerXMLHandler(const BeerXMLHandler &iOther);
    BeerXMLHandler & operator=(const BeerXMLHandler &iOther);
    BeerXMLHandler & operator=(BeerXMLObject* ipObject);
    BeerXMLHandler & operator=(const BeerXMLObject* ipObject);
    virtual ~BeerXMLHandler();
    
    // Handled object
    BeerXMLObject * operator->() const;
    operator BeerXMLObject *();
    operator const BeerXMLObject *() const;
    bool operator!() const;
    bool operator==(const BeerXMLHandler &iOther) const;
    
    /*
    * Beer XML entities cast operators
    * Warning non NULL pointers are not addref'ed
    * returns :
    *   NULL : underlying object is not of the asked type
    *   non null pointer instance : cast successfull!
    */
    operator Hop*() const;
    operator Fermentable*() const;
    operator Misc*() const;
    operator Water*() const;
    operator Yeast*() const;
    operator Mash*() const;
    operator MashStep*() const;
    operator Style*() const;
    operator Recipe*() const;

    /*
    * Create BeerXMLObject from a beer xml file
    *
    * params
    *	[in] iBeerXMLFile : the file path of the beer xml
    *
    * returns
    *	0 : success
    *	1 : file does not exist
    *	2 : not a valid beer xml file
    */
    int CreateFromFile(const QString &iBeerXMLFile);

    /*
    * Save BeerXMLObject to xml file
    *
    * params
    *   [in] iBeerXMLFile : the file path of the beer xml
    *
    * returns
    *   0 : success
    *   1 : error
    */
    int SaveToFile(const QString &iBeerXMLFile) const;

    /*
    * Create BeerXMLObject from a DOM xml node
    *
    * params
    *   [in] iNode : the DOM xml node to parse
    *
    * returns
    *   0 : success
    *   1 : error
    */
    int CreateFromXMLNode(const QDomNode &iNode);

private:

    // Letter
   BeerXMLObject *_pObject;
};

#endif

